package com.yc.dao;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.yc.Idao.GoodsIDao;
import com.yc.Idao.GoodsInfoIDao;
import com.yc.utils.StringUtil;

	public class GoodsInfoDao implements GoodsInfoIDao{

		@Override
		public List<Map<String, Object>> find(Map<String, Object> map) {
			DBHelper db = new DBHelper();
			//动态的SQL语句拼接
			StringBuffer sb = new StringBuffer();
			sb.append("select g_id, g_name, g_price, g_image from f_good where 1 = 1 ");
			//参数集合
			List<Object> params = null;
			//判断map是否为空   意味着无查询条件
			if(null == map || map.isEmpty()) {
				return db.findMutile(sb.toString());
			}
			//意味着有查询参数
			params = new ArrayList<Object>();
			//通过参数  拼接SQL对应条件
			if(map.get("g_name") != null) {
				sb.append(" and g_name like '%" + map.get("g_name") + "%'");
			}
			System.out.println(sb.toString());
			System.out.println(params.toArray());
			return db.findMutile(sb.toString(), params.toArray());
		}

		public List<Map<String, Object>> finds( String g_name) {
			DBHelper db= new DBHelper();
			String sql = "select g_id, g_name, g_price, g_image from f_good where 1 = 1 and g_name like '%'||?||'%'";
			
			return db.findMutile(sql, g_name);
			// TODO Auto-generated method stub
		}
		
		/*public List<Map<String, Object>> finds(String gname){
			DBHelper db = new DBHelper();
			String sql = "select g_id, g_name, g_price, g_image from f_good where 1 = 1 ";
			List<Object> params = new ArrayList<Object>();
			if(!StringUtil.checkNull(gname)) {
				sql +=" and gname like '%'||?||'%' ";
				params.add(gname);
			}
			System.out.println(sql);
			return db.findSingle(sql,gname);
		}*/
		
		
		
		/*public int Updatep( double money, String g_name) {
			String sql = "update f_good set g_price = ? where g_name = ? ";
			int re = 0;
			re = db.update(sql, );
			if(re == 0) {
				// 付款成功
				return -1;
			}else {
				sql = "update f_room set r_status = 3 where r_id = ?";
				return db.update(sql, r_id);
			}
			
			
		}*/
		
		/*public int updateP(Map<String, Object> map) {
			DBHelper db = new DBHelper();
			//动态的SQL语句拼接
			StringBuffer sb = new StringBuffer();
			sb.append("update f_good set  g_price = ?  where g_id = ? and 1 = 1 ");
			//参数集合
			List<Object> params = null;
			//意味着有查询参数
			params = new ArrayList<Object>();
			System.out.println(sb.toString());
			System.out.println(params.toArray());
			return db.update(sb.toString(), params.toArray());
		}*/

		public int  Updatep(Number g_price, String g_id) {
			DBHelper db = new DBHelper();
			String sql = "update f_good set  g_price = ?  where g_id = ? ";
			
			int re = db.update(sql, g_price, g_id);
			return db.update(sql,  g_id);
		}

			
			
		}


